package javalearning.fileoperate.fileIO;

import java.io.*;

/**
 * IO流分类
 * 按方向：
 * 输入流
 * 输出流
 * 按类型
 * 字节流：
 * 字节输入流 InputStream
 * 字节输出流 OutputStream
 * 字符流：
 * 字符输入流 Reader
 * 字符输出流 Writer
 */
public class FileIOStream {
    public static void main(String[] args) throws IOException {
        File file = new File("D:\\测试.txt");
        readFile(file);
        return;
    }

    private static void readFile(File file) throws IOException {
        if (!file.exists()) {
            return;
        }
        FileInputStream fileInputStream = new FileInputStream(file);
        int length = fileInputStream.readAllBytes().length;
        FileInputStream fileInputStream1 = new FileInputStream(file);
        int byt = fileInputStream1.read();
        if (byt != -1) {
            System.out.print((char) byt);
        }
        fileInputStream.close();
    }

    private static void writeFile(File file) throws IOException {
        if (file.exists()) {
            System.out.println("exist");
        } else {
            boolean res = file.createNewFile();
            System.out.println(res);
        }
        FileOutputStream fileOutputStream = new FileOutputStream(file, true);
        String des = "hello, world,哈哈哈" + "\n";
        byte[] bytes = des.getBytes();
        for (int i = 0; i < 10; i++) {
            fileOutputStream.write(bytes);
        }
        fileOutputStream.close();
    }
}

class A {
    public void aVoid() throws FileNotFoundException {
        File file = new File("D:\\a"); // 文件对象
        FileInputStream fileInputStream = new FileInputStream(file); // 字节输入流
        InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream); //io转换流
        FileReader fileReader = new FileReader(file); // 字符输入流
        BufferedReader bufferedReader = new BufferedReader(fileReader); // 字符缓冲流
        FileOutputStream fileOutputStream = new FileOutputStream(file, true);
    }
}
